package com.house.controller;

import com.house.service.CityService;
import com.house.utils.Code;
import com.house.utils.Result;
import com.house.vo.CityVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @version 1.0
 * @Author OhygC
 * @since 1.0
 */
@Api("城市信息")
@RestController
@RequestMapping("city")
public class CityController {
    @Resource
    private CityService cityService;

    @ApiOperation(value = "查询所有城市",notes = "不用传任何参数")
    @PostMapping("findAllCity")
    public Result findAllCity(@RequestBody Map<String,Object> params){
        Map<String, Object> map = new HashMap<>();
        int tatol = cityService.findTatol(params);
        map.put("tatol", String.valueOf(tatol));
        if (tatol != 0){
            //Page<User> usersByName = cityService.findUsersByName(params);
            List<Map<String,CityVO>> allCity = cityService.findAllCity(params);
            //map.put(usersByName);
            map.put("allCity", allCity);
            return new Result(Code.GET_OK,map,"查询成功");
        }
        return new Result(Code.GET_ERR,"查询失败");
    }
}
